package com.chookss.tools;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class PermissionSpUtils {
    private static final String spFileName = "permissionsUtils";
    private static final int mode = Context.MODE_PRIVATE;
    private static String Basic = "navigation";

    public static String getString(Context context, String key,
                                   final String defaultValue) {
        final SharedPreferences settings = context.getSharedPreferences(spFileName, mode);
        return settings.getString(Basic+key, defaultValue);
    }

    public static void setString(Context context, final String key,
                                 final String value) {
        final SharedPreferences settings = context.getSharedPreferences(spFileName, mode);
        settings.edit().putString(Basic+key, value).commit();
    }

    public static boolean getBoolean(Context context, final String key,
                                     final boolean defaultValue) {
        final SharedPreferences settings = context.getSharedPreferences(spFileName, mode);
        return settings.getBoolean(Basic+key, defaultValue);
    }

    public static void setBoolean(Context context, final String key,
                                  final boolean value) {
        final SharedPreferences settings = context.getSharedPreferences(spFileName, mode);
        settings.edit().putBoolean(Basic+key, value).commit();
    }

    public static void clearAll(Context context) {
        final SharedPreferences settings = context.getSharedPreferences(spFileName, mode);
        SharedPreferences.Editor editor = settings.edit();
        editor.clear();
        editor.commit(); // 提交更改
    }
}
